package cn.juque.jdfsystem.controller.message;

import cn.juque.common.base.BaseResponseVO;
import cn.juque.common.constants.MessageEnum;
import cn.juque.jdfsystem.controller.BaseFileController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>FileInfoController</li>
 * </ul>
 * @date 2023-12-19 10:13:40
 **/
@Slf4j
@Controller
@RequestMapping("/jdf/message/file")
public class FileInfoMessageController extends BaseFileController {

    /**
     * 查看文件
     *
     * @param id 文件ID
     * @param platformId 平台ID
     * @param sign 签名
     * @param timestamp 有效的时间戳
     * @param response HttpServletResponse
     */
    @GetMapping(value = "/view/{id}")
    @Override
    public void view(@PathVariable String id, String platformId, String sign, Long timestamp, HttpServletResponse response) throws IOException {
        super.view(id, platformId, sign, timestamp, response);
    }

    /**
     * 上传
     *
     * @param file  文件
     * @param scope 作用域
     * @param path  所属目录
     * @return 文件id
     * @throws IOException IOException
     */
    @PostMapping(value = "/upload")
    @ResponseBody
    public BaseResponseVO<String> uploadFile(@RequestParam("file") MultipartFile file, String platformId, Integer scope, String path) throws IOException {
        String fileId = super.upload(file, platformId, scope, path);
        return new BaseResponseVO<>(MessageEnum.OK, fileId);
    }

    /**
     * 查找文件所在机器
     *
     * @param fileId 文件ID
     * @return BaseResponseVO
     */
    @GetMapping(value = "/find/{id}")
    public BaseResponseVO<List<String>> findFile(@PathVariable("id") String fileId) {
        return new BaseResponseVO<>(MessageEnum.OK, super.find(fileId));
    }

    /**
     * 检查文件是否在当前机器
     *
     * @return BaseResponseVO
     */
    @GetMapping(value = "/checkFile/{id}")
    public BaseResponseVO<Boolean> check(@PathVariable("id") String fileId) {
        return new BaseResponseVO<>(MessageEnum.OK, super.checkFile(fileId));
    }
}
